package com.guan.ordering_sys.generator.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.exception.BaseException;
import com.guan.ordering_sys.generator.entity.Desk;
import com.guan.ordering_sys.generator.entity.DeskRecord;
import com.guan.ordering_sys.generator.mapper.DeskMapper;
import com.guan.ordering_sys.generator.mapper.DeskRecordMapper;
import com.guan.ordering_sys.generator.service.DeskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guan.ordering_sys.param.DeskParam;
import com.guan.ordering_sys.vo.DeskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 许少萍
 * @since 2021-06-23
 */
@Service
public class DeskServiceImpl extends ServiceImpl<DeskMapper, Desk> implements DeskService {

    @Autowired
    DeskMapper deskMapper;

    @Autowired
    DeskRecordMapper recordMapper;

    /**
     * 列表
     * @param deskVoPage
     * @return
     */
    @Override
    public IPage<DeskVo> orderList(Page<DeskVo> deskVoPage) {
        IPage<DeskVo> DeskVoIPage = deskMapper.selectOrderList(deskVoPage);
        return DeskVoIPage;
    }
    /**
     * 修改
     * @param deskParam
     * @return
     */
    @Override
    public int update(DeskParam deskParam) {
        if (deskMapper.update(deskParam) > 0) {
            DeskRecord deskRecord = new DeskRecord();
            deskRecord.setDeskId(deskParam.getDesk_id());
            deskRecord.setUsed(deskParam.getUsed());
            deskRecord.setPhone(deskParam.getPhone());
            deskRecord.setClientName("关远键");
            deskRecord.setBeginTime(deskParam.getBegin_time());
            deskRecord.setEndTime(deskParam.getEnd_time());
            recordMapper.insert(deskRecord);
            return 1;
        } else {
            throw new BaseException(StateCode.DAO_EXCEPTION);
        }
    }
}
